package com.agenda.comum;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import com.agenda.model.RespostaRequisicao;

public abstract class ObjectRecebedorInformacao implements ReceberInformacao {

	protected Socket sck;

	protected RespostaRequisicao resposta;

	@Override
	public void receber(Socket sck) throws Exception {
		this.sck = sck;
		ObjectInputStream objectInput = new ObjectInputStream(sck.getInputStream());

		//Resposta padrão.
		resposta = new RespostaRequisicao(false, "");

		receber(objectInput);
	}

	@Override
	public void enviarResposta(Socket sck) throws Exception {
		ObjectOutputStream objectInput = new ObjectOutputStream(sck.getOutputStream());
		objectInput.writeObject(getReposta());
		responder(sck.getOutputStream());
	}

	protected void responder(OutputStream outputStream) throws Exception {

	}

	protected RespostaRequisicao getReposta() {
		return resposta;
	}

	public abstract void receber(ObjectInputStream objectInput) throws Exception;
}
